package com.apes.scm.income.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.fileserver.File;
import com.apes.framework.util.ApesConst;
import com.apes.scm.masterdata.finance.model.AmtReceipt;
import com.apes.scm.masterdata.finance.model.BankAccount;
import com.apes.scm.masterdata.finance.model.PaymentMethodType;
import com.apes.scm.masterdata.frame.model.Dept;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * @BelongsProject: apes-server
 * @BelongsPackage: com.apes.fico.finance.model.gl
 * @ClassName: MoneyIncomeItem
 * @Author: pyb
 * @CreateTime: 2020-03-09 13:57
 * @Description: 资金收入明细
 * @Version: 1.0
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = MoneyIncomeItem.CONST_TABLE_NAME)
public class MoneyIncomeItem extends BaseModel {
    public final static String CONST_TABLE_NAME = "money_income_item";


    @Id
    @Column(name = "id", nullable = false, length = 120)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "资金收入明细单", padding = 8)
    @Comment("资金收入明细单号")
    private String id;

//    @NotNull
//    @ManyToOne(fetch = FetchType.LAZY)
//    @JoinColumn(name = "income_type_id", referencedColumnName = "id")
//    @Comment("收入类型编码")
//    private IncomeType incomeType;


    //    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "amt_receipt_id", referencedColumnName = "id")
    @Comment("资金收入类型")
    private AmtReceipt amtReceipt;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "payment_method_type", referencedColumnName = "id", nullable = false)
    @Comment("收款方式")
    private PaymentMethodType paymentMethodType;

    @Column(name = "receivable_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("应收金额")
    private double receivableAmount = 0;

    @Column(name = "income_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("收入金额")
    private double incomeAmount = 0;

    @Column(name = "remark", length = 200)
    @Comment("摘要")
    private String remark;

    @Column(name = "account", length = 64)
    @Comment("账号")
    private String account;

    @Column(name = "account_name", length = 64)
    @Comment("账户简称")
    private String accountName;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "customer_Dept_id", referencedColumnName = "id")
    @Comment("部门编码")
    private Dept customerDept; //部门

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "customer_id", referencedColumnName = "id")
    @Comment("挂账客户")
    private PartyRole customer;  //挂账客户

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "bank_account_id", referencedColumnName = "id")
    @Comment("收款账号")
    private BankAccount bankAccount;  //收款账号

    @Column(name = "weichat_flow", length = 256)
    @Comment("微信交易流水")
    private String weichatFlow;

    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "money_income", referencedColumnName = "id")
    @Comment("资金收入单")
    private MoneyIncome moneyIncome;

    @Column(name = "platform_management_fee", nullable = false, columnDefinition = ApesConst.FIELD_16_4_0)
    @Comment("平台管理费")
    private double platformManagementFee = 0;

    @File
    @Lob
    @Comment("图片")
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "imgs", columnDefinition = "CLOB")
    private String imgs;

    @Column(name = "account_number", length = 250)
    @Comment("银行账号")
    private String accountNumber; // 银行账号

    @Transient
    private String billNumber; //票据号码

    @Transient
    private double amount = 0;

    @Transient
    private String note;
}
